"""
定义一个全局变量：money，用来记录银行卡余额（默认5000000）
定义一个全局变量：name，用来记录客户姓名（启动程序输入）
定义如下的函数：
    查询余额函数
    存款函数
    取款函数
    主菜单函数
要求：
程序启动后要求输入客户姓名
查询余额、存款、取款后都会返回主菜单
存款、取款后，都应显示一下当前余额
客户选择退出或输入错误，程序会退出，否则一直运行
"""
money = 5000000
name = input('please enter your name')

# 查余额
def balance():
    print('-----balance-----')
    print(f'{name},hello,your balance:{money}')
    menu()  # 回主页

# 存款
def save():
    print('-----save-----')
    save_money = float(input(f'{name},hello,please enter your deposit amount:'))
    global money
    if save_money > 0:
        money = money + save_money
        print(f'{name},hello,you made a success deposit of {save_money} yuan')
        print(f'{name},hello,your balance:{money}')
        menu()  # 回主页
    else:
        print('error')
        menu()

# 提款
def withdraw():
    print('-----withdraw-----')
    withdraw_money = float(input(f'{name},hello,please enter your withdrawal amount'))
    global money
    if withdraw_money > 0 and withdraw_money < money:
        money = money - withdraw_money
        print(f'{name},hello,you made a success withdrawal of {withdraw_money} yuan')
        print(f'{name},hello,your balance:{money}')
        menu()  # 回主页
    else:
        print('error')
        menu()

# 主菜单
def menu():
    print('-----menu-----')
    print(f'{name},hello,welcome to my ATM machine,please select operation')
    print('to check the balance,please enter 1')
    print('to save money,please enter 2')
    print('to withdraw the money,please enter 3')
    print('to exit,please enter 4')
    select_num = int(input('please make your choice'))
    if select_num == 1:
        balance()
    elif select_num == 2:
        save()
    elif select_num == 3:
        withdraw()
    else:
        quit()
        
menu()


